package com.dzm.xgb.core.controller.api;


import com.dzm.common.result.R;
import com.dzm.common.util.JwtUtils;
import com.dzm.xgb.core.pojo.entity.BorrowInfo;
import com.dzm.xgb.core.service.BorrowInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Dzm
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/api/core/borrowInfo")
public class BorrowInfoController {

    @Autowired
    private BorrowInfoService borrowInfoService;

    @PostMapping("/auth/save")
    public R saveBorrowerInfo(@RequestBody BorrowInfo borrowInfo, HttpServletRequest request) {
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);

        borrowInfoService.saveBorrowerInfo(userId, borrowInfo);

        return R.ok().message("借款申请已提交！");
    }

    @GetMapping("/auth/getBorrowInfoStatus")
    public R getBorrowInfoStatus(HttpServletRequest request) {
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);

        Integer status = borrowInfoService.getBorrowerInfoStatus(userId);

        return R.ok().data("borrowInfoStatus", status);
    }

}

